package com.allen.workflow.listener.task;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.springframework.stereotype.Component;

/**
 * @program: spring-boot-demo
 * @className UserTaskListener
 * @description: 业务任务监听demo
 * @author: zp
 * @create: 2024-08-16 14:50
 * @Version 1.0
 **/
@Slf4j
@Component
@AllArgsConstructor
public class UserTaskListener extends BusinessTaskListener{

    private RuntimeService runtimeService;

    @Override
    protected void onCreate(WorkTask delegateTask) {
        log.info("创建任务:{},任务id:{}", delegateTask.getTaskName(), delegateTask.getTaskId());
        String processInstanceId = delegateTask.getDelegateTask().getProcessInstanceId();
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).active().singleResult();
    }

    @Override
    protected void onComplete(WorkTask delegateTask) {
        log.info("任务完成:{},任务id:{}", delegateTask.getTaskName(), delegateTask.getTaskId());
        String processInstanceId = delegateTask.getDelegateTask().getProcessInstanceId();
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).active().singleResult();
    }

    @Override
    protected void onAssignment(WorkTask delegateTask) {

    }

    @Override
    protected void onDelete(WorkTask delegateTask) {

    }

    @Override
    protected void onUpdate(WorkTask delegateTask) {

    }

    @Override
    protected void onTimeout(WorkTask delegateTask) {

    }
}
